;(function () {
  const elevator = document.querySelector('.xtx-elevator')
  window.addEventListener('scroll', function () {
    const n = document.documentElement.scrollTop
    elevator.style.opacity = n >= 300 ? 1 : 0
  })
  const backtop = document.querySelector('#backTop')
  backtop.addEventListener('click', function () {
    window.scrollTo(0, 0)
  })
})()
;(function () {
  const list = document.querySelector('.xtx-elevator-list')
  const goodsNew = document.querySelector('.xtx_goods_new')
  const popular = document.querySelector('.xtx_goods_popular')
  const brand = document.querySelector('.xtx_goods_brand')
  const topic = document.querySelector('.xtx_goods_topic')
  list.addEventListener('click', function (e) {
    if (e.target.tagName === 'A' && e.target.dataset.name) {
      const n = e.target.dataset.name
      switch (n) {
        case 'new':
          window.scrollTo(0, goodsNew.offsetTop)
          break
        case 'popular':
          window.scrollTo(0, popular.offsetTop)
          break
        case 'brand':
          window.scrollTo(0, brand.offsetTop)
          break
        case 'topic':
          window.scrollTo(0, topic.offsetTop)
          break
        default:
      }
    }
  })
  window.addEventListener('scroll', function () {
    list.querySelector('a.active') &&
      list.querySelector('a.active').classList.remove('active')
    const n = document.documentElement.scrollTop
    if (n >= goodsNew.offsetTop && n < popular.offsetTop) {
      list.querySelector('a[data-name="new"]').classList.add('active')
    } else if (n >= popular.offsetTop && n < brand.offsetTop) {
      list.querySelector('a[data-name="popular"]').classList.add('active')
    } else if (n >= brand.offsetTop && n < topic.offsetTop) {
      list.querySelector('a[data-name="brand"]').classList.add('active')
    } else if (n >= topic.offsetTop) {
      list.querySelector('a[data-name="topic"]').classList.add('active')
    }
  })
})()
